﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using BaiduEditor.PluginInterface;
namespace FirstPlugin.UI
{
	public partial class AdGroupsForm : Form
	{
		PluginResult result;
		public AdGroupsForm(PluginResult result)
		{
			this.result = result;
			InitializeComponent();
			Init();
		}

		public void Init()
		{
			this.StartPosition = FormStartPosition.CenterScreen;
			this.FormBorderStyle = FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
		}

		private void btnAdGroups_Click(object sender, EventArgs e)
		{
			if (result.IsSuccessful)
			{
				List<PluginAdGroup> adGroups = (List<PluginAdGroup>)result.Value;
				String msg = adGroups.Count.ToString() + Environment.NewLine;

				foreach (PluginAdGroup adGroup in adGroups)
				{
					msg += adGroup.ID + Environment.NewLine +
						   adGroup.Name + Environment.NewLine +
						   adGroup.LocalStatus + Environment.NewLine +
						   Environment.NewLine;
				}

				MessageBox.Show(msg);
			}
			else
			{
				String msg = result.Errors.Count.ToString() + Environment.NewLine;
				foreach (PluginError err in result.Errors)
				{
					msg += err.Id.ToString() + Environment.NewLine +
						   err.ErrorObjectName + Environment.NewLine +
						   err.ErrorType.ToString() + Environment.NewLine +
						   err.Message + Environment.NewLine +
						   Environment.NewLine;
				}
				MessageBox.Show(msg);
			}
		}
	}
}
